package com.isaac.edu.controller;

import com.isaac.edu.pojo.Resume;
import com.isaac.edu.service.IResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/Resume")
public class ResumeController {


    @Autowired
    private IResumeService resumeService;


    @RequestMapping("/all")
    @ResponseBody
    public List<Resume> getAllResume(){
        return  resumeService.showList();
    }

    @RequestMapping("/index")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("index");
        return modelAndView;
    }

    @RequestMapping("/indexPage")
    public ModelAndView showResumeList(){
        ModelAndView modelAndView = new ModelAndView();
        List<Resume> resumes = resumeService.showList();
        modelAndView.addObject("resumeList",resumes);
        modelAndView.setViewName("resume");
        return modelAndView;
    }

    @RequestMapping("/resumeFtl")
    public ModelAndView showfltResume(){
        ModelAndView modelAndView = new ModelAndView();
        List<Resume> resumes = resumeService.showList();
        modelAndView.addObject("resumeList",resumes);
        modelAndView.setViewName("/freemaker/resumeftl.ftl");
        return modelAndView;
    }

    @RequestMapping("/insert")
    public ModelAndView insertOne(Resume resume){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("resume");
        resumeService.insertOne(resume);
        List<Resume> resumes = resumeService.showList();
        modelAndView.addObject("resumeList",resumes);
        return modelAndView;

    }

    @RequestMapping("/update")
    public ModelAndView updateOne(Resume resume){
        resumeService.updateOne(resume);
        return showResumeList();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public boolean deleteOne(Resume resume){
        return resumeService.deleteOne(resume);
    }



}
